package com.luocj.looook.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.luocj.looook.R;
import com.luocj.looook.base.BaseActivity;
import com.luocj.looook.fragment.Fragment1;
import com.luocj.looook.fragment.Fragment2;
import com.luocj.looook.utils.Constant;
import com.luocj.looook.utils.SPUtils;

import java.util.ArrayList;

public class WelcomeActivity extends BaseActivity {

    private ViewPager mViewPager;
    private Fragment1 fragment1 = new Fragment1();
    private Fragment2 fragment2 = new Fragment2();
    private ArrayList<Fragment> fragments;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_welcome;
    }

    @Override
    protected void initView() {
        mViewPager = findViewById(R.id.viewpager_welcome);

        fragments = new ArrayList<>();
        fragments.add(fragment1);
        fragments.add(fragment2);

        MyAdapter myAdapter = new MyAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(myAdapter);
    }

    @Override
    protected void initData() {
        SPUtils.putBoolean(WelcomeActivity.this, Constant.IS_FIRST_IN, false);
    }

    private class MyAdapter extends FragmentStatePagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }
    }
}
